package com.gxa.servlet;

import com.gxa.entity.Community;
import com.gxa.service.CommunityService;
import com.gxa.service.impl.CommunityServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet("/page/community/preupdate")
public class PreUpdateServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        String cid = req.getParameter("cid");

        CommunityService communityService = new CommunityServiceImpl();
        Community community = null;
        try {
            community = communityService.queryByID(Integer.parseInt(cid));
        } catch (SQLException e) {
            throw new RuntimeException(e);
        } finally {
        }

        req.setAttribute("community",community);
        req.getRequestDispatcher("edit.jsp").forward(req,resp);

    }
}
